package utl.mofen.dbHandler;

import org.apache.log4j.Logger;

import com.google.gson.JsonArray;
import utl.mofen.delphi.cds.DeltaUnPackage;
import utl.mofen.handler.JSonConfigWriter;


public class CDSUpdateHandler extends DBBaseHandler {
	private static final Logger logger = Logger.getLogger(CDSUpdateHandler.class);

	public void doAction() throws Exception {
		if (config.has("list")) {
			JsonArray upList = config.get("list").getAsJsonArray();
			for (int i = 0; i < upList.getAsJsonArray().size(); i++) {
				DeltaUnPackage unPack = new DeltaUnPackage();
				String dataKey = upList.get(i).getAsString();
				String data = new String(dataKeyStream.getStream(dataKey),
						"utf-8");
				
				logger.info("开始保存数据" + dataKey+ ",数据长度:" + data.length());
				unPack.setDBOperator(this.dbOpera);
				unPack.setPackString(data);
				unPack.execute();
				dbOpera.clearBatch();
				dbOpera.addSQL4BatchExecute(unPack.getSqlHead());
				dbOpera.addSQLs4BatchExecute(unPack.getSqlList());

				if (isTrace) {
					JSonConfigWriter.writeTraceSQL(this.resultJsonStream,
							unPack.getUpdateSQL());
				}
				
				dbOpera.executeBatchSQL();
				
				logger.info("成功保存数据" + dataKey);
				unPack = null;
			}
		}
	}
}
